//
//  FilterView.m
//  W2MD
//
//  Created by zhudongwei on 14/10/29.
//  Copyright (c) 2014年 zhudongwei. All rights reserved.
//

#import "FilterView.h"
#import "WZhuSeBan.h"
#import "YZhuSeBan.h"
#import "ChunSeBan.h"
#import "FilterLevel2View.h"
#import "AMBlurView.h"
#import "TMingSe.h"
#import "SXModel.h"
#import "FMDatabase.h"
#define BGColor [[UIColor alloc] initWithRed:0.f green:0.f blue:0.f alpha:0.6];
#define DefaultCornerRadius 8.f

#define rect1 CGRectMake(60,56,70,31);
#define rect2 CGRectMake(184,56,70,31);
#define rect3 CGRectMake(244,56,70,31);


@interface FilterView()<ClothesItemViewDelegate,UIAlertViewDelegate>
{
    UIButton *tmpBtn;
    YZhuSeBan * yZhuSeBan;
    WZhuSeBan * wZhuSeBan;
    ChunSeBan * chunSeBan;
    TMingSe *tmingse;
    NSMutableDictionary *infoDic;
    NSString *l2Key;
    ClothesItemView *deleteItemView;
}
@property(nonatomic,strong) IBOutlet UIButton *btn1;
@property(nonatomic,strong) IBOutlet UILabel *lbl1;
@end


@implementation FilterView

-(void)initBtn
{
    self.iPhone=NO;
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    //CGFloat width = size.width;
    CGFloat height = size.height;
    if (height<500) {
        self.iPhone=YES;
    }
    
    self.seg.selectedSegmentIndex=1;
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(segValueChange:) name:@"SEGVALUE" object:nil];
    
    UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = self.bounds;
    [self addSubview:visualEffectView];
    [self sendSubviewToBack:visualEffectView];
    
    self.rubbishBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *rubbishImg=[UIImage imageNamed:@"rubbish40@2x.png"];
    
    //self.rubbishBtn.backgroundColor=[UIColor redColor];
    
    [self.rubbishBtn setImage:rubbishImg forState:UIControlStateNormal];
    if (self.iPhone) {
        self.rubbishBtn.frame=CGRectMake(self.frame.size.width-75-25, self.frame.size.height-240+30, 100, 100);
    } else
        self.rubbishBtn.frame=CGRectMake(self.frame.size.width-75-25, self.frame.size.height-173+30, 100, 100);
    
    [self.rubbishBtn addTarget:self action:@selector(rubbishAct) forControlEvents:UIControlEventTouchUpInside];
    [self.rubbishBtn setContentMode:UIViewContentModeCenter];
    [self addSubview:self.rubbishBtn];
    
//    [yZhuSeBan removeFromSuperview];
//    [wZhuSeBan removeFromSuperview];
//    [chunSeBan removeFromSuperview];
    
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"YZhuSeBan" owner:self options:nil];
    yZhuSeBan = [nib objectAtIndex:0];
    yZhuSeBan.tag = 111;
    yZhuSeBan.frame =  CGRectMake(10, self.kuanshiBtn.frame.origin.y+CGRectGetHeight(self.kuanshiBtn.frame)+20, yZhuSeBan.frame.size.width, yZhuSeBan.frame.size.height);//CGPointMake(0, 210);
    [yZhuSeBan.zhuseBan addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [yZhuSeBan.peiseBan addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [yZhuSeBan.yanseshuxing addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    yZhuSeBan.layer.masksToBounds = YES;
    yZhuSeBan.layer.cornerRadius = DefaultCornerRadius;
    //[self.level1ViewBG addSubview:yZhuSeBan];
    
    nib = [[NSBundle mainBundle] loadNibNamed:@"WZhuSeBan" owner:self options:nil];
    wZhuSeBan = [nib objectAtIndex:0];
    wZhuSeBan.tag = 121;
    wZhuSeBan.frame =  CGRectMake(10, self.kuanshiBtn.frame.origin.y+CGRectGetHeight(self.kuanshiBtn.frame)+20, wZhuSeBan.frame.size.width, wZhuSeBan.frame.size.height);
    [wZhuSeBan.zhuseBan addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [wZhuSeBan.yanseshuxing addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    wZhuSeBan.layer.masksToBounds = YES;
    wZhuSeBan.layer.cornerRadius = DefaultCornerRadius;
    //[self.level1ViewBG addSubview:wZhuSeBan];
    
    nib = [[NSBundle mainBundle] loadNibNamed:@"ChunSeBan" owner:self options:nil];
    chunSeBan = [nib objectAtIndex:0];
    chunSeBan.tag = 131;
    chunSeBan.frame =  CGRectMake(10, self.kuanshiBtn.frame.origin.y+CGRectGetHeight(self.kuanshiBtn.frame)+20, chunSeBan.frame.size.width, chunSeBan.frame.size.height);
    [chunSeBan.chunseBan addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    chunSeBan.layer.masksToBounds = YES;
    chunSeBan.layer.cornerRadius = DefaultCornerRadius;
    //[self.level1ViewBG addSubview:chunSeBan];
    
    nib = [[NSBundle mainBundle] loadNibNamed:@"TMingSe" owner:self options:nil];
    tmingse = [nib objectAtIndex:0];
    tmingse.tag = 141;
    tmingse.frame =  CGRectMake(10, self.kuanshiBtn.frame.origin.y+CGRectGetHeight(self.kuanshiBtn.frame)+20, tmingse.frame.size.width, tmingse.frame.size.height);
    [tmingse.tmingban addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    tmingse.layer.masksToBounds = YES;
    tmingse.layer.cornerRadius = DefaultCornerRadius;
    //[self.level1ViewBG addSubview:tmingse];
    
    yZhuSeBan.hidden = YES;
    wZhuSeBan.hidden = YES;
    chunSeBan.hidden = YES;
    tmingse.hidden = YES;

}

- (void)rubbishAct
{
    NSString *str = [NSString stringWithFormat:@"确定清除筛选服饰吗?"];
    UIAlertView *alerw  = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alerw.tag=888;
    [alerw show];
}

-(IBAction)segValueChange:(id)sender
{
    [self removeSubView];
    UISegmentedControl *tmpSeg = (UISegmentedControl*)sender;
    tmpSeg.tintColor= [self colorWithHexString:@"#9E59E4"];
    NSLog(@"!!!seg%f",tmpSeg.frame.origin.y);
//    SXModel *model=[SXModel shareModel];
//    if (model.segValue!=10) {
//        tmpSeg.selectedSegmentIndex=model.segValue;
//        model.segValue=10;
//    }
    switch (tmpSeg.selectedSegmentIndex) {
        case 0:
        {
            //self.btnIV.image = [UIImage imageNamed:@"chunselei.png"];
            self.filterType = EM_FT_ChunSe;
            chunSeBan.hidden = NO;
            [self enableBtns];
        }
            break;
        case 1:
        {
            //self.btnIV.image = [UIImage imageNamed:@"youzhuselei.png"];
            self.filterType = EM_FT_YouZhuSe;
            yZhuSeBan.hidden = NO;
            [self enableBtns];
        }
            break;
        case 2:
        {
            //self.btnIV.image = [UIImage imageNamed:@"wuzhuselei.png"];
            self.filterType = EM_FT_WuZhuSe;
            wZhuSeBan.hidden = NO;
            [self enableBtns];
        }
            break;
        default:
            break;
    }
}

-(IBAction)btnClick:(id)sender
{
    UIButton *btn = (UIButton*)sender;
    
    if (self.initFlag == 1 || self.initFlag == 2 || self.initFlag == 3) {
        if (btn.tag == self.initFlag) {
            return;
        }
        else if(btn.tag != self.initFlag)
        {
            switch (btn.tag) {
                case 2:
                {

                    [self removeSubView];
                    
                    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
                                     animations:^{
                                         [self disableBtns];
                                         self.btnIV.image = [UIImage imageNamed:@"youzhuselei.png"];
                                         tmpBtn.frame = CGRectMake(self.yZSBtn.frame.origin.x, self.yZSBtn.frame.origin.y, tmpBtn.frame.size.width , tmpBtn.frame.size.height);
                                         tmpBtn.titleLabel.font = [UIFont systemFontOfSize:15];
                                         self.yZSBtn.frame = CGRectMake(60, 56, self.yZSBtn.frame.size.width , self.yZSBtn.frame.size.height);
                                         yZhuSeBan.hidden = NO;
                                         self.yZSBtn.titleLabel.font = [UIFont systemFontOfSize:17];
                                         self.filterType = EM_FT_YouZhuSe;
                                         self.initFlag = (int)btn.tag;
                                     } completion:^(BOOL finished) {
                                         tmpBtn = self.yZSBtn;
                                         [self enableBtns];
                                     }];
                }
                    break;
                case 3:
                {
                    [self removeSubView];
                    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
                                     animations:^{
                                         [self disableBtns];
                                         self.btnIV.image = [UIImage imageNamed:@"wuzhuselei.png"];
                                         tmpBtn.frame = CGRectMake(self.wZSBtn.frame.origin.x, self.wZSBtn.frame.origin.y, tmpBtn.frame.size.width , tmpBtn.frame.size.height);
                                         tmpBtn.titleLabel.font = [UIFont systemFontOfSize:15];
                                         self.wZSBtn.frame = CGRectMake(60, 56, self.wZSBtn.frame.size.width , self.wZSBtn.frame.size.height);
                                         self.wZSBtn.titleLabel.font = [UIFont systemFontOfSize:17];
                                         wZhuSeBan.hidden = NO;
                                         self.filterType = EM_FT_WuZhuSe;
                                         self.initFlag = (int)btn.tag;
                                     } completion:^(BOOL finished) {
                                         tmpBtn = self.wZSBtn;
                                         [self enableBtns];
                                     }];
                }
                    break;
                case 1:
                {
                    [self removeSubView];
                    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
                                     animations:^{
                                         [self disableBtns];
                                         self.btnIV.image = [UIImage imageNamed:@"chunselei.png"];
                                         tmpBtn.frame = CGRectMake(self.cSBtn.frame.origin.x, self.cSBtn.frame.origin.y, tmpBtn.frame.size.width , tmpBtn.frame.size.height);
                                         tmpBtn.titleLabel.font = [UIFont systemFontOfSize:15];
                                         self.cSBtn.frame = CGRectMake(60, 56, self.cSBtn.frame.size.width , self.cSBtn.frame.size.height);
                                         self.cSBtn.titleLabel.font = [UIFont systemFontOfSize:17];
                                         chunSeBan.hidden = NO;
                                         self.filterType = EM_FT_ChunSe;
                                         self.initFlag = (int)
                                         btn.tag;
                                     } completion:^(BOOL finished) {
                                         tmpBtn = self.cSBtn;
                                         [self enableBtns];
                                     }];
                }
                    break;
                default:
                    break;
            }
        }
    }
    
}
-(void)removeSubView
{
    yZhuSeBan.hidden = YES;
    wZhuSeBan.hidden = YES;
    chunSeBan.hidden = YES;
    tmingse.hidden = YES;
}

-(void)disableBtns
{
    self.wZSBtn.userInteractionEnabled = NO;
    self.yZSBtn.userInteractionEnabled = NO;
    self.cSBtn.userInteractionEnabled = NO;

}

-(void)enableBtns
{
//    self.wZSBtn.userInteractionEnabled = YES;
//    self.yZSBtn.userInteractionEnabled = YES;
//    self.cSBtn.userInteractionEnabled = YES;
    [self.filterViewDelegate actionWithColorChange:self.filterType];
}

-(void)level1ViewBGHidden
{
    self.filterLevel2View.hidden = NO;
//    [UIView animateWithDuration:0.5 animations:^{
//        //self.level1ViewBG.center = CGPointMake(-160, self.level1ViewBG.center.y);
//        self.filterLevel2View.center = CGPointMake(160, self.filterLevel2View.center.y);
//    }];
    [UIView animateWithDuration:0.3 animations:^{
        self.level1ViewBG.center = CGPointMake(-160, self.level1ViewBG.center.y);
    } completion:^(BOOL finished) {
        self.level1ViewBG.hidden = YES;
        [UIView animateWithDuration:0.3 animations:^{
            self.filterLevel2View.center = CGPointMake(160, self.filterLevel2View.center.y);
        }];
        
    }];
}
-(void)level1ViewBGShow
{
    [UIView animateWithDuration:0.5 animations:^{
        self.level1ViewBG.center = CGPointMake(480, self.level1ViewBG.center.y);
        self.level1ViewBG.center = CGPointMake(160, self.level1ViewBG.center.y);
    }];
}

-(void)initView
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FilterLevel2View" owner:self options:nil];
    _filterLevel2View = [nib objectAtIndex:0];
    _filterLevel2View.tag = 14;
    _filterLevel2View.frame = CGRectMake(320, 114, _filterLevel2View.frame.size.width, _filterLevel2View.frame.size.height);
    [_filterLevel2View.backbtn addTarget:self action:@selector(BackToLevel1:) forControlEvents:UIControlEventTouchUpInside];
    _filterLevel2View.hidden = YES;
    [self addSubview:_filterLevel2View];
}

-(IBAction)btnClickAction:(id)sender
{
    UIButton *btn = (UIButton*)sender;
    //[self level1ViewBGHidden];
    [self.filterViewDelegate actionWithSubmenuType:(int)btn.tag withFilterType:self.filterType];
    
}
-(IBAction)quxiaoAction:(id)sender;
{
    [self removeFromSuperview];
    [self.filterViewDelegate actionWithCancel];
}

-(IBAction)quedingAction:(id)sender
{
    [self removeFromSuperview];
    [self.filterViewDelegate actionWithOK:nil];
}
-(IBAction)BackToLevel1:(id)sender
{
    //self.level1ViewBG.center = CGPointMake(480, self.level1ViewBG.center.y);
    self.level1ViewBG.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.filterLevel2View.center = CGPointMake(-160, self.filterLevel2View.center.y);
        //self.level1ViewBG.center = CGPointMake(-160, self.level1ViewBG.center.y);
    } completion:^(BOOL finished) {
        self.filterLevel2View.hidden = YES;
        [UIView animateWithDuration:0.3 animations:^{
            self.level1ViewBG.center = CGPointMake(160, self.level1ViewBG.center.y);
        }];
        
    }];
}


-(void)initFushiInfo:(NSMutableDictionary*)ifdic
{
    [self initBtn];
    
    infoDic = ifdic;
    //[self dataFromDB:infoDic];
    _path=[[NSString alloc] init];
    
    self.xijieLbl.textAlignment=NSTextAlignmentRight;
    
    NSArray *keyValue = [ifdic allKeys];
    
    if ([keyValue count]>0) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BackgroundView" owner:self options:nil];
        BackgroundView * backgroundView = [nib objectAtIndex:0];
        backgroundView.tag = 151;
        backgroundView.hidden = YES;
        [backgroundView.btn addTarget:self action:@selector(removeEditStatus:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:backgroundView];
        
        for (int i = 0; i<[keyValue count]; i++) {
            NSMutableDictionary *dic = [ifdic objectForKey:[keyValue objectAtIndex:i]];
            NSMutableDictionary *l2dic = [dic objectForKey:@"l2key"];
            
            ClothesItemView *clothesItemView = [[ClothesItemView alloc] initWithFrame:CGRectMake(8+8*i+70*i, 37, 70, 70)];
            clothesItemView.infodic = l2dic;
            
            [clothesItemView showBtnStatusHL:NO];
            clothesItemView.clothesIVDelegate = self;
            clothesItemView.infoTag = i;
            switch (i) {
                case 0:
                    self.clothesIV1 =clothesItemView;
                    break;
                case 1:
                    self.clothesIV2 =clothesItemView;
                    break;
                case 2:
                    self.clothesIV3 =clothesItemView;
                    break;
                case 3:
                    self.clothesIV4 =clothesItemView;
                    break;
                default:
                    break;
            }
            [self addSubview:clothesItemView];
            if (i == [keyValue count]-1) {
                if (i >= 3) {
                    return;
                }
                else{
                    self.addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                    self.addBtn.frame = CGRectMake(8+8*i+70*(i+1), 28, 70, 70);
                    [self.addBtn setImage:[UIImage imageNamed:@"filter_add.png"] forState:UIControlStateNormal];
                    [self.addBtn addTarget:self action:@selector(addYifuClick:) forControlEvents:UIControlEventTouchUpInside];
                    [self addSubview:self.addBtn];
                }
            }
        }
    }
    
    l2Key = [self.clothesIV1.infodic objectForKey:@"id"];
    //[self itemClickWith:self.clothesIV1];
    //[self.clothesIV1 setDefaultClick];
    [self performSelector:@selector(initBtnClick) withObject:nil afterDelay:0];
}

-(void)initBtnClick
{
    [self.clothesIV1 setDefaultClick];
}

-(void)addYifuClick:(id)sender
{
    //[self initBtn];
    [self.filterViewDelegate actionAddClothes];
}

-(void)itemClickWith:(ClothesItemView*)clothesIV
{
    //[[NSNotificationCenter defaultCenter] postNotificationName:@"CLOSETABLE" object:nil];
    
    l2Key = [clothesIV.infodic objectForKey:@"id"];
    NSLog(@"infoDic=%@",clothesIV.infodic);
    SXModel *model=[SXModel shareModel];
    model.tuanKey=[clothesIV.infodic valueForKey:@"Icon"];
    model.clickItem=YES;
    NSLog(@"l2key%@",l2Key);
    [self.clothesIV1 showBtnStatusHL:NO];
    [self.clothesIV2 showBtnStatusHL:NO];
    [self.clothesIV3 showBtnStatusHL:NO];
    [self.clothesIV4 showBtnStatusHL:NO];
    self.seg.hidden = NO;
    //[self initBtn];
    NSMutableDictionary* clothesdic = [infoDic objectForKey:l2Key];
    NSMutableDictionary *colorDic = [clothesdic objectForKey:@"color"];
    NSString *colorType = [colorDic objectForKey:@"colorType"];
    if ([colorType isEqualToString:@"chunse"]) {
        //[self btnClick:self.cSBtn];
        yZhuSeBan.hidden=NO;
        wZhuSeBan.hidden=NO;
        chunSeBan.hidden=NO;
        tmingse.hidden=YES;
        [self.seg setSelectedSegmentIndex:0];
        [self segValueChange:self.seg];
        [chunSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"wuzhuse"])
    {
        //[self btnClick:self.wZSBtn];
        yZhuSeBan.hidden=NO;
        wZhuSeBan.hidden=NO;
        chunSeBan.hidden=NO;
        tmingse.hidden=YES;
        [self.seg setSelectedSegmentIndex:2];
        [self segValueChange:self.seg];
        [wZhuSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"youzhuse"])
    {
        //[self btnClick:self.yZSBtn];
        yZhuSeBan.hidden=NO;
        wZhuSeBan.hidden=NO;
        chunSeBan.hidden=NO;
        tmingse.hidden=YES;
        [self.seg setSelectedSegmentIndex:1];
        [self segValueChange:self.seg];
        [yZhuSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"touming"])
    {
        //[self btnClick:self.yZSBtn];
        //[self.seg setSelectedSegmentIndex:1];
        self.seg.hidden = YES;
        self.filterType = EM_FT_ToumingSe;
        tmingse.hidden = NO;
        yZhuSeBan.hidden=YES;
        wZhuSeBan.hidden=YES;
        chunSeBan.hidden=YES;
        //[self segValueChange:self.seg];
        [tmingse showDesc:colorDic];
    }
    
    
    
    NSMutableDictionary *xijieDic = [clothesdic objectForKey:@"xijie"];
    
    NSMutableString *text = [[NSMutableString alloc] init];
    NSArray *vauleArr = [xijieDic allValues];
    if ([vauleArr count]>0) {
        for (int i = 0; i < [vauleArr count]; i++) {
            NSMutableDictionary *dic = [vauleArr objectAtIndex:i];
            if ([dic objectForKey:@"checkValue"]) {
                NSMutableDictionary *tmpDic = [dic objectForKey:@"checkValue"];
                NSLog(@"checkValueStr%@",[tmpDic objectForKey:@"Name"]);
                [text appendString:[tmpDic objectForKey:@"Name"]];
                [text appendString:@" "];
            }
        }
        self.xijieLbl.text = text;
    }
    else{
        self.xijieLbl.text = @"";
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"REFRESHZHUSEBAN" object:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"REFRESHKUANSHI" object:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"REFRESHTUAN" object:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"REFRESHPEISE" object:nil];
    
}
-(void)itemLongPressWith:(ClothesItemView*)clothesIV
{
    BackgroundView * backgroundView = (BackgroundView *)[self viewWithTag:151];
    backgroundView.hidden = NO;
    //[clothesIV showEditIcon:YES];
    [self.clothesIV1 showEditIcon:YES];
    [self.clothesIV2 showEditIcon:YES];
    [self.clothesIV3 showEditIcon:YES];
    [self.clothesIV4 showEditIcon:YES];
    self.addBtn.hidden = YES;
}
-(void)removeEditStatus:(id)sender
{
    if ([infoDic count]>0) {
        [self resetFushiItem];
        [self initFushiInfo:infoDic];
    } else {
        
    }

}

-(void)resetFushiItem
{
    [self.clothesIV1 removeFromSuperview];
    [self.clothesIV2 removeFromSuperview];
    [self.clothesIV3 removeFromSuperview];
    [self.clothesIV4 removeFromSuperview];
    self.clothesIV1 = nil;
    self.clothesIV1 = nil;
    self.clothesIV1 = nil;
    self.clothesIV1 = nil;
    BackgroundView * backgroundView = (BackgroundView *)[self viewWithTag:151];
    [backgroundView removeFromSuperview];
    backgroundView = nil;
}

-(void)itemDelete:(ClothesItemView*)clothesIV
{
    NSString *str = [NSString stringWithFormat:@"确定要删除%@?",clothesIV.lbl.text];
    UIAlertView *alerw  = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alerw.tag=666;
    [alerw show];
    deleteItemView = clothesIV;
}

-(NSString*)getCheckL2Key
{
    return l2Key;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==666) {
        switch (buttonIndex) {
            case 0:
            {
                //return;
            }
                break;
            case 1:
            {
                switch (deleteItemView.infoTag) {
                    case 0:
                    {
                        [self.clothesIV1 removeFromSuperview];
                        self.clothesIV1 = nil;
                        [infoDic removeObjectForKey:[deleteItemView.infodic objectForKey:@"id"]];
                    }
                        break;
                    case 1:
                    {
                        [self.clothesIV2 removeFromSuperview];
                        self.clothesIV2 = nil;
                        [infoDic removeObjectForKey:[deleteItemView.infodic objectForKey:@"id"]];
                    }
                        break;
                    case 2:
                    {
                        [self.clothesIV3 removeFromSuperview];
                        self.clothesIV3 = nil;
                        [infoDic removeObjectForKey:[deleteItemView.infodic objectForKey:@"id"]];
                    }
                        break;
                    case 3:
                    {
                        [self.clothesIV4 removeFromSuperview];
                        self.clothesIV4 = nil;
                        [infoDic removeObjectForKey:[deleteItemView.infodic objectForKey:@"id"]];
                    }
                        break;
                    default:
                        break;
                }
            }
                break;
            default:
                break;
        }
        NSLog(@"------------- %ld",(long)buttonIndex);
        deleteItemView = nil;
        SXModel *model=[SXModel shareModel];
        if ([model.selectedTuanDic valueForKey:[deleteItemView.infodic valueForKey:@"Icon"]]) {
            [model.selectedTuanDic removeObjectForKey:[deleteItemView.infodic valueForKey:@"Icon"]];
        }
        
        if ([model.selectedPeiseDic valueForKey:[deleteItemView.infodic valueForKey:@"Icon"]]) {
            [model.selectedPeiseDic removeObjectForKey:[deleteItemView.infodic valueForKey:@"Icon"]];
        }
            
    }  else if (alertView.tag==888){
        switch (buttonIndex) {
            case 0:
            {
                //return;
            }
                break;
            case 1:
            {
                [infoDic removeAllObjects];
            }
                break;
            default:
                break;
        }
        
    }
    
    [self.filterViewDelegate actionDeleteClothes];
}

-(void)reloadInfo
{
    NSMutableDictionary* clothesdic = [infoDic objectForKey:l2Key];
    NSMutableDictionary *colorDic = [clothesdic objectForKey:@"color"];
    NSString *colorType = [colorDic objectForKey:@"colorType"];
    if ([colorType isEqualToString:@"chunse"]) {
        //[self btnClick:self.cSBtn];
        [chunSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"wuzhuse"])
    {
        //[self btnClick:self.wZSBtn];
        [wZhuSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"youzhuse"])
    {
        //[self btnClick:self.yZSBtn];
        [yZhuSeBan showDesc:colorDic];
    }
    else if([colorType isEqualToString:@"touming"])
    {
        //[self btnClick:self.yZSBtn];
        [tmingse showDesc:colorDic];
    }
    NSMutableDictionary *xijieDic = [clothesdic objectForKey:@"xijie"];
    NSMutableString *text = [[NSMutableString alloc] init];
    NSArray *vauleArr = [xijieDic allValues];
    if ([vauleArr count]>0) {
        for (int i = 0; i < [vauleArr count]; i++) {
            NSMutableDictionary *dic = [vauleArr objectAtIndex:i];
            if ([dic objectForKey:@"checkValue"]) {
                NSMutableDictionary *tmpDic = [dic objectForKey:@"checkValue"];
                [text appendString:[tmpDic objectForKey:@"Name"]];
                [text appendString:@" "];
            }
        }
        self.xijieLbl.text = text;
        self.xijieLbl.textAlignment = NSTextAlignmentRight;
    }
}

- (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}

#pragma mark - Data Base
-(void)dataFromDB:(NSMutableDictionary *)searchDic
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:_path];
    NSMutableDictionary *clothesDic = (NSMutableDictionary *)[infoDic objectForKey:[self getCheckL2Key]];
    
    if ([db open]) {
        
        NSString *sql = [NSString stringWithFormat:@"select distinct bs.ID,bs.Name from [BelongsStyle_DetailStyle] bsds inner join [Pic_BelongsStyle] bs on bs.ID = bsds.[BelongsStyleId] where bsds.BelongsTypeID=%@ and bsds.Female_DetailStyleId is not null",[self getCheckL2Key]];
        FMResultSet *result = [db executeQuery:sql];
        
        NSMutableDictionary *topKeyValue1 = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [topKeyValue1 removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *name = [result stringForColumn:@"Name"];
            [_mutableDictionayData setObject:name forKey:@"Name"];
            
            [topKeyValue1 setValue:_mutableDictionayData forKey:name];
        }
        
        [clothesDic setObject:topKeyValue1 forKey:@"xijie"];
        [db close];
    }
    
}

- (void)readyDatabse {
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"dd21.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    [self getPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dd21.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

- (void)getPath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    _path = [documentsDirectory stringByAppendingPathComponent:@"dd21.sqlite"];
}
//-(void)resetDetailView
//{
//    [chunSeBan showDesc:nil];
//    [wZhuSeBan showDesc:nil];
//    [yZhuSeBan showDesc:nil];
//}
@end
